package com.relatev.minecraft.TRMExample.listener;

import com.relatev.minecraft.TRMExample.TRMExample;
import com.relatev.minecraft.TRMobAPI.TRMobAPI;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Zombie;

public class TRTask implements Runnable {
    
    public static void init() {
        Bukkit.getScheduler().runTaskTimer(TRMExample.MainPlugin, new TRTask(), 5 * 20, 5 * 20);
    }
    
    @Override
    public void run() {
        for (Entity ent : TRMobAPI.getAPI().getTRMobManager().getTRMob("com.relatev.minecraft.TRMExample.TestZombie").getLivingMobs()) {
            Zombie zombie = (Zombie) ent;
            if (zombie.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() <= zombie.getHealth() + 5) {
                zombie.setHealth(zombie.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
            } else {
                zombie.setHealth(zombie.getHealth() + 5);
            }
        }
    }
}
